<?php
if (!defined('WY_ROOT')) exit;


class bindwechat extends Wechat_Controller
{
    function __construct(){
		
        parent::__construct();
    }
    function index() {
		
		$this->assign('title',"绑定微信");
        $this->getView('bindwechat.php')->outPut();
    }
	function bind(){
	   $account=$_POST['account'];
	   $psw=$_POST['psw'];
	   $user_info=$this->model("wechart")->fetch_one("users","username='".$account."'");
	   if(!$account){
		   $_r['status']=2;
		   echo json_encode($_r);
		   exit;
	   }
	   $psw=md5(md5($psw));
	   if($psw!=$user_info['userpass']){
		   $_r['status']=2;
		   echo json_encode($_r);
		   exit;
	   }
	   $data['openid']=$_SESSION['openid'];
	   $this->model("wechart")->update("users",$data,"id=".$user_info['id']);
	   $_r['status']=1;
	   echo json_encode($_r);
	   exit;
    }
    
} ?>